Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make termination condition config declarative #4984

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

victordibia
Copy link
Collaborator

Why are these changes needed?

Step 1 in making components in agentchat natively declarative.

from autogen_agentchat.conditions import StopMessageTermination, MaxMessageTermination 

max_term = MaxMessageTermination(5)
stop_term = StopMessageTermination() 

or_term = max_term | stop_term
print(or_term.dump_component() )
 
print(max_term.dump_component())

Results

ComponentModel(provider='autogen_agentchat.base._termination._OrTerminationCondition', 
component_type='termination', version=1, component_version=1, description=None, 
config={'conditions': [{'provider': 'autogen_agentchat.conditions.MaxMessageTermination', '
component_type': 'termination', 'version': 1, 'component_version': 1, 
'config': {'max_messages': 5}}, {'provider': 'autogen_agentchat.conditions.StopMessageTermination', 
'component_type': 'termination', 'version': 1, 'component_version': 1, 'config': {}}]})
ComponentModel(provider='autogen_agentchat.conditions.MaxMessageTermination', 
component_type='termination', version=1, component_version=1, 
description=None, config={'max_messages': 5})

Related issue number

Closes #4983

Checks

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 56.05%. Comparing base (6bc285c) to head (489db97).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4984       +/-   ##
===========================================
- Coverage   72.42%   56.05%   -16.37%     
===========================================
  Files         112       67       -45     
  Lines        6494     5755      -739     
===========================================
- Hits         4703     3226     -1477     
- Misses       1791     2529      +738     
Flag Coverage Δ
unittests 56.05% <ø> (-16.37%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


component_config_schema = AndTerminationConditionConfig
component_type = "termination"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we include component override for cleaner path?

Copy link
Collaborator Author

@victordibia victordibia Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,

@ekzhu , for Or/AndTerm, are you fine with making it a public TerminationCondition and exporting this to give it a clean path? Anyway, these are used in developer code (or_term = stop_term and max_term) so might be a good idea?

Something like from ._termination import TerminatedException, TerminationCondition, OrTerminationCondition, AndTerminationCondition

Copy link
Collaborator

@ekzhu ekzhu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just to make sure, we will use the override for a cleaner provider path right?



class TerminationCondition(ABC):
class TerminationCondition(ABC, Component[Any]):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class TerminationCondition(ABC, Component[Any]):
class TerminationCondition(ABC, Component[BaseModel]):

Copy link
Collaborator Author

@victordibia victordibia Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was gonna ask about this ... it leads to a flurry of pyright/mypy errors .. was not sure how to deal :) . Given that each base class have their own ConfigModels ..

Also, ComponentLoader does not want an abstract class (TerminationCondition) and it will be too disruptive to make a concrete BaseTerminationCondition and then refactor the rest of the code to do this.

 conditions = [
            ComponentLoader.load_component(
                condition_model, TerminationCondition)
            for condition_model in config.conditions
        ]

Copy link
Member

@jackgerrits jackgerrits Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pattern should be that the base interface is a ComponentLoader but not a Component since itself is not loadable after all!

But this does make it difficult to generically dump a component...

Should be written as (after making the interface a ComponentLoader):

TerminationCondition.load_component(...)

Unsure if that fixes your issue though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support declarative configs for TerminationCondition
3 participants